package ods_supplier

import (
	"reflect"
	"server/global"
	"strings"
)


type OdsSupplier struct {
	global.BaseModel
	Name    string `json:"name" form:"name" gorm:"column:name;comment:姓名;size:191;"`
	Dept    string `json:"dept" form:"dept" gorm:"column:dept;comment:单位;size:191;"`
	Phone   string `json:"phone" form:"phone" gorm:"column:phone;comment:电话;size:191;"`
	Email   string `json:"email" form:"email" gorm:"column:email;comment:电子邮箱;size:191;"`
	Supply  string `json:"supply" form:"supply" gorm:"column:supply;comment:提供内容;size:250;"`
	Remarks string `json:"remarks" form:"remarks" gorm:"column:remarks;comment:备注;size:191;"`
}


func (m *OdsSupplier) TableName() string {
	return "ods_supplier"
}


func (m *OdsSupplier) Save() error {
	err := global.SysDB.Save(&m).Error
	return err
}


func GetColLabel(m interface{}) map[string]string {
	t := reflect.TypeOf(m)
	colLabel := make(map[string]string)
	for k := 0; k < t.NumField(); k++ {
		gorm := t.Field(k).Tag.Get("gorm")
		if len(gorm) > 20 { // --gorm处理
			cc := strings.Split(gorm, ";")
			if len(cc) > 1 {
				var ck, cv string
				for _, c := range cc {
					cs := strings.Split(c, ":")
					if len(cs) > 1 && cs[0] == "column" {
						ck = cs[1]
					}
					if len(cs) > 1 && cs[0] == "comment" {
						cv = cs[1]
					}
				}
				if len(ck) > 0 && len(cv) > 0 {
					colLabel[ck] = cv
				}
			}
		}
	}
	return colLabel
}
